package com.tanhua.server.service;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.dubbo.config.annotation.Reference;
import com.tanhua.dubbo.server.api.RecommendUserApi;
import com.tanhua.dubbo.server.pojo.RecommendUser;
import com.tanhua.dubbo.server.vo.PageInfo;
import com.tanhua.server.vo.TodayBest;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author feihao
 * @version 1.0
 * @date 2021/6/29 20:32
 */

//调用dubbo服务的接口查询mogodb的数据：
@Service
public class RecommendUserService {

    @Reference(version = "1.0.0")
    private RecommendUserApi recommendUserApi;

    //更具id查询今日佳人
    public TodayBest queryTodayBest(Long userId) {
        RecommendUser recommendUser = this.recommendUserApi.queryWithMaxScore(userId);
        if (recommendUser == null) {
            return null;
        }


        TodayBest todayBest = new TodayBest();
        todayBest.setId(recommendUser.getUserId());  // 设置id
        Long fate = (long) Math.floor(recommendUser.getScore());
        todayBest.setFateValue(fate);
        return todayBest;
    }

    //根据id查询推荐人列表
    public PageInfo<RecommendUser> findRecommendationUserList(Long id, Integer page, Integer pagesize) {
        return recommendUserApi.queryPageInfo(id, page, pagesize);
    }


    //查询探花cardList
    public List<RecommendUser> queryCardList(Long id, Integer count) {
        return recommendUserApi.queryCardList(id, count);
    }


    /**
     * 查询得分：
     *
     * @param userId  用户的Id
     * @param userId1 推荐给谁的用户id:
     * @return
     */
    public Double queryScore(Long userId, Long userId1) {
        RecommendUser recommendUser = recommendUserApi.queryPersonInfo(userId1, userId);
        if (!ObjectUtil.isEmpty(recommendUser)) {
            return recommendUser.getScore();
        }
        //如果没得，返回默认得分：
        return 90D;
    }
}

//package com.tanhua.server.service;
//
//import com.alibaba.dubbo.config.annotation.Reference;
//import com.tanhua.dubbo.server.api.RecommendUserApi;
//import com.tanhua.dubbo.server.pojo.RecommendUser;
//import com.tanhua.dubbo.server.vo.PageInfo;
//import com.tanhua.server.vo.TodayBest;
//import org.springframework.stereotype.Service;
//
///**
// * 负责与dubbo服务进行交互
// */
//@Service
//public class RecommendUserService {
//
//    @Reference(version = "1.0.0")
//    private RecommendUserApi recommendUserApi;
//
//    public TodayBest queryTodayBest(Long userId) {
//        RecommendUser recommendUser = this.recommendUserApi.queryWithMaxScore(userId);
//        if (null == recommendUser) {
//            return null;
//        }
//
//        TodayBest todayBest = new TodayBest();
//        todayBest.setId(recommendUser.getUserId());
//
//        //缘分值
//        double score = Math.floor(recommendUser.getScore());//取整,98.2 -> 98
//        todayBest.setFateValue(Double.valueOf(score).longValue());
//
//        return todayBest;
//    }
//
//    public PageInfo<RecommendUser> findRecommendationUserList(Long userId, Integer page, Integer pageSize) {
//        return this.recommendUserApi.queryPageInfo(userId, page, pageSize);
//    }
//}
